package edu.fsu.cs.SHPE;

import java.net.ConnectException;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SessionListAdapter extends BaseAdapter {

	private SessionContainer sessionContainer;
	private Context context;
	
	public SessionListAdapter(Context context, String url) throws ConnectException{
		this.context = context;
		sessionContainer = new SessionContainer(url);
 	}
	
	public void setViewableSessionsByTrackId(long id){
		sessionContainer.setViewableSessionsByTrackId(id);
	}
	
	
	@Override
	public int getCount() {
		return sessionContainer.getViewableList().size();
	}

	@Override
	public Object getItem(int position) {
		return sessionContainer.getViewableList().get(position);
	}

	@Override
	public long getItemId(int position) {
		return sessionContainer.getViewableList().get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		LayoutInflater inFlate = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
		View v = inFlate.inflate(R.layout.sessionitem, null);
		TextView tmp;
		
		Session tmpSession = sessionContainer.getViewableList().get(position);
		
		if(tmpSession.getTitle() != null){
			tmp = (TextView)v.findViewById(R.id.txtTitle);
			tmp.setText(tmpSession.getTitle());
		}
		
		if(tmpSession.getStartTime() != null){
			tmp = (TextView) v.findViewById(R.id.txtStartTime);
			tmp.setText(tmpSession.getStartTime() + "- ");
		}
		
		if(tmpSession.getEndTime() != null){
			tmp = (TextView) v.findViewById(R.id.txtEndTime);
			tmp.setText(tmpSession.getEndTime());
		}
		
		if(tmpSession.getRoom() != null){
			tmp = (TextView) v.findViewById(R.id.txtRoom);
			tmp.setText(tmpSession.getRoom());
		}
		
		/*
		if(tmpSession.getDescription() != null){
			tmp = (TextView)v.findViewById(R.id.txtDescription);
			tmp.setText(tmpSession.getDescription());
			tmp.setVisibility(TextView.VISIBLE);
		}
		*/

		/*
		if(tmpConference.getWebsite() != null){
			tmp = (TextView)v.findViewById(R.id.txtWebsite);
			tmp.setText(tmpConference.getWebsite());
			//Linkify.addLinks(tmp, Linkify.WEB_URLS);
			tmp.setVisibility(TextView.VISIBLE);
		}
		*/

		/*
		if(tmpConference.getEmail() != null){
			tmp = (TextView)v.findViewById(R.id.txtEmail);
			tmp.setText(tmpConference.getEmail());
			//Linkify.addLinks(tmp, Linkify.EMAIL_ADDRESSES);
			tmp.setVisibility(TextView.VISIBLE);
		}
		*/

		/*
		if(tmpConference.getPhone() != null){
			tmp = (TextView) v.findViewById(R.id.txtPhone);
			tmp.setText(tmpConference.getPhone());
			//Linkify.addLinks(tmp, Linkify.PHONE_NUMBERS);
			tmp.setVisibility(TextView.VISIBLE);
		}
		*/
		
		

		/*
		if(tmpSession.getAddress() != null){
			tmp = (TextView)v.findViewById(R.id.txtAddress);
			tmp.setText(tmpSession.getAddress() + ',' + tmpSession.getCity() + ',' + tmpSession.getProvince() + ',' +
					tmpSession.getPostalCode());
			//Linkify.addLinks(tmp, Linkify.MAP_ADDRESSES);
			tmp.setVisibility(TextView.VISIBLE);
		}
		*/

		//ImageButton btn = (ImageButton)v.findViewById(R.id.btnDisplay);
		//btn.setId((int)tmpConference.getId());

		return v;
	}

}
